#include "../includes/processor.h"
#include "../includes/heat_sensor.h"

void hs_init(){
	//set up a port for inputs
	ADCinit();
}


void ADCinit(void)
{
	//select channel AN1 and enable ADC
   ADCON0 = 0x05;

   ADCON1=0x00;

   ADCON2=0x80;
}

void start_conversion(){
	ADCON0 |= 0x02; 
}

int conversion_done(){
	int tmp = ADCON0 & 0x02;
	return tmp == 0; 
}

unsigned float get_ADC_result(){
	
	int ADResult;
	int ADResultH;
	int ADResultL;

	ADResultH = ADRESH;
	ADResultL = ADRESL;
	ADResult = (((ADResultH  << 8) & 0x300) + ADResultL)>>2;

	return ADResult;
}